<template>
    <div>
       <el-form   :model="model" :rules="rules" ref="ruleForm" llabel-width="100px" class="demo-ruleForm">

           <el-form-item label="盘号" prop="Number">
               <el-input v-model="model.Number"></el-input>
           </el-form-item>

           <el-form-item class="page-box-footer">
              <el-button type="primary" @click="submitForm">{{ isUpdate?'立即保存':'立即创建' }}</el-button>
                <el-button @click="resetForm">重置</el-button>
           </el-form-item>
       </el-form>
   </div>
</template>

<script>
export default{
    props: {
        model: {
            require: true,
            type: Object
        },
        isUpdate: {
            require: true,
            type: Boolean
        }
   },
   data(){
       return{
           PanHaoList:[],
           rules:{
               Number:{required:true,message:"请输入盘号名称",trigg:'blur'}
           }
       }    
   },
   created(){
       this.getPanHaoAll();
   },
   methods:{
       submitForm(){
           this.$refs['ruleForm'].validate((valid)=>{
                if (valid) {

                    if(this.isUpdate){
                        this.put();
                    }
                    else{
                        this.add();
                    }

                } else {
                    this.showNotify('请输入必填项');
                    return false;
                }
             
           });
       },
    resetForm() {
        this.$refs['ruleForm'].resetFields();
      },
       add(){
        this.$http.postForm('/api/PanHao',{model:this.model},{loading:this.$loading()})
        .then(res=>{
            this.$emit('callback');
        })
       },
       //修改
       put(){
       this.$http.putForm('/api/PanHao',{model:this.model},{loading:this.$loading()})
       .then((res)=>{
           this.$emit('callback');
       })
     },
     
     getPanHaoAll(){
       this.$http.get('/api/PanHao/GetAll')
       .then(res=>{
           this.PanHaoList=res.Data ;
       })
     }
   }
}
</script>

<style>

</style>